const express = require('express');
const { json, urlencoded } = require('body-parser');
const cors = require('cors');
const ip = require('internal-ip');
const config = require('./config/server');
const parse = require('./parse');
const app = express();

app.use(json({ limit: '50m' })).use(urlencoded({ limit: '1024m', extended: false })).use(cors());

(async () => {
  let apis = await parse();
  apis.forEach(api => app[api.method](api.url, api.service));
})();

app.listen(config.port, async () => {
  console.log(`
      Mock服务器运行于：
      http://localhost:${config.port}
      http://${await ip.v4()}:${config.port}
  `);
});